[#assign menucode="companyPay"]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <title>财务管理</title>
    <link href="/res/css/respective/order/back-order.css" rel="stylesheet">
</head>
<body>
[#-- ispurchaser是否是采购商 --]
[#assign ispurchaser = Session.currentRole.roleType == 1]
<div class="warp">
[#include "/front/common/front_headAzt.html"]

    <div class="backcontent">
    [#include "/front/common/front_leftAzt.html"] 
        <div class="back-main">
            <div class="inner">
                <div class="title">项目交易款</div>
                <div class="backTab">
                    <ul>
                       	<li [#if queryParam.payResult == '-1']class="on"[/#if] data-tab="-1">[#if ispurchaser]待支付[#else]应收款[/#if][#if initCount > 0]<span class="orange"><i></i>${initCount!}</span>[/#if]</li>
                       	<li [#if queryParam.payResult == '1']class="on"[/#if] data-tab="1">[#if ispurchaser]已支付[#else]已收款[/#if][#if submitCount > 0]<span class="orange"><i></i>${submitCount!}</span>[/#if]</li>
                       	[#if ispurchaser]<li [#if queryParam.payResult == '0']class="on"[/#if] data-tab="0">支付失败 [#if failCount > 0]<span class="orange"><i></i>${failCount!}</span>[/#if]</li>[/#if]
                    </ul>
                </div>
                <form id="orderPayForm" action="/order/payList" method="get">
	                <!-- 当前页码 -->
	                <input type="hidden" id="pageNo" name="pageNo" value="${page.pageNum!}">
	                <!-- 订单tab -->
	                <input type="hidden" id="payResult" name="payResult" value="${queryParam.payResult!}">
	                <div class="back-status"> 
	                    <input style="width: 175px;" type="text" id="keyword" name="keyword" value="${queryParam.keyword!}" placeholder="请输入询价单名称/订单编号" class="orderInput orderInput1" />
	                    <span>  
	                    	<label>[#if ispurchaser]卖[#else]买[/#if]家名称：</label>
	                    	<input type="text" class="orderInput orderInput2"
			                     [#if ispurchaser]id="sellerName" name="sellerName" value="${queryParam.sellerName!}"
			                     [#else]id="buyerName" name="buyerName" value="${queryParam.buyerName!}"[/#if]/>
			            </span>
			            [#if ispurchaser]<span>来源公司：
			            <select name="buyerId" id="buyerId">
			            	<option value="">全部</option>
			            	<option value="${companyId}">本公司</option>
				            [#list childCompanyList as childCompany]
				            <option value="${childCompany.id}" [#if queryParam.buyerId??][#if childCompany.id?string==queryParam.buyerId]selected[/#if][/#if]>${childCompany.companyName}</option>
				            [/#list]
				        </select></span>
			            [/#if]
			            <span>下单日期：<input type="text" id="sdate" name="sdate" value="${queryParam.sdate!}" class="orderInput dateInput" /> - <input type="text" id="edate" name="edate" value="${queryParam.edate!}" class="orderInput dateInput" /></span>
	                	<a href="javascript:search()">搜索</a>
	                </div>
                </form>
                <table class="titleTable">
                    <tbody>
                    <tr style="background-color: #f8f8f8;">
                        <td width="35%">询价单名称</td>
                        <td width="20%">金额</td>
                        <td width="20%">订单状态</td>
                        <td width="25%">[#if queryParam.payResult == '0']失败原因[#else]操作[/#if]</td>
                    </tr>
                    </tbody>
                </table>
                [#if orderPayList?? && orderPayList?size > 0]
                    <div class="dataTable">
                    [#list orderPayList as orderPay]
                    <table data-orderId='${orderPay.orderId!}' data-buyerCompanyId="${orderPay.buyerCompanyId!}" data-buyerUserId="${orderPay.buyerUserId!}"
                           data-sellerCompanyId="${orderPay.sellerCompanyId!}" data-sellerUserId="${orderPay.sellerUserId!}" data-ifChildBuy="[#if orderPay.isChild??]${orderPay.isChild?string}[/#if]">
                        <tbody>
                        <tr>
                            <th colspan="5">
	                            <div class="alltd">[#if ispurchaser && orderPay.isFenBuy]<img src="/res/images/unit/fen.png" alt=""/>[/#if]下单时间：${(orderPay.ordertime?string("yyyy-MM-dd HH:mm:ss"))!}　　订单号：${orderPay.orderNumber!} &nbsp; &nbsp; &nbsp;
	                            	<div class="cname">[#if ispurchaser]卖家：${CommonUtil.getSimpleStr(orderPay.sellerCompanyName, 20)}[#if orderPay.isFenBuy]&nbsp; &nbsp; &nbsp;分公司：${orderPay.buyerCompanyName}[/#if][#else][#if orderPay.isChild]买家：${orderPay.parentName}&nbsp; &nbsp; &nbsp;分公司：${orderPay.buyerCompanyName}[#else]买家：${orderPay.buyerCompanyName}[/#if][/#if]
	                            		<div></div>
	                            	</div>
	                            </div>
	                         </th>
                        </tr>
                        <tr>
                            <td width="35%"><p class="name"><a href="/xmh/${orderPay.enquiryId!}" target="_Blank" title="${orderPay.projectName!}">${orderPay.enquiryName!}</a></p></td>
                            <td width="20%"><b class="orange">￥${orderPay.totalPrice!?string('0.00')}</b>
                                    		[#if orderPay.ifBatchPay?? && orderPay.ifBatchPay == 1 && (orderPay.payResult == 1 || orderPay.payResult == 2)]
	                                        <div class="pici">
	                                            <span class="pname" [#if orderPay.payResult == -1]data-tip="batchPayUnpaid"[#else]data-tip="batchPay"[/#if]>分批</span>
	                                            <div class="pcdown">
	                                                <img src="/res/third/nice-validator/images/loading.gif" alt="loading"/>
	                                            </div>
	                                        </div>
                                    		[/#if]
                            </td>
                            <td width="20%">
                                <p>
                                    [#if orderPay.payResult == 0]
  						        	支付失败
                                    [#elseif orderPay.payResult == -1]
                                   	 待支付
                                    [#elseif orderPay.payResult == 1]
                                	已支付
                                    [#elseif orderPay.payResult == 2]
                                   	已支付
                                    [/#if]
                                </p>
                                [#if ispurchaser]<p><a href="/order/payDetail/${orderPay.orderId!}" target="_Blank">详情</a></p>[/#if]
                            </td>
                            <td width="25%">
                            [#if ispurchaser]
	                            [#if orderPay.payResult==-1]
                                    [#--<a href="javascript:void(0)" onclick="checkPay('${orderPay.orderId!}')" class="btn">立即支付</a>--]
                                    <a href="/order/pay_on/${orderPay.orderId!}/${orderPay.id!}" class="btn" target="_Blank">立即支付</a>
	                            [#elseif orderPay.payResult==0]
                                    ${orderPay.rejectReason!}
	                            [#elseif orderPay.payResult==1]
	                            [#elseif orderPay.payResult==2][/#if]
	                        [#else]
	                        	<a href="/order/payDetail/${orderPay.orderId}" class="btn" target="_Blank">查看</a>
	                       	[/#if]
                            </td>
                        </tr>      
                        </tbody>
                    </table>
                    [/#list]
                    </div>
                    <div class="backpage">
                    共${page.total!}条记录<span class="orange">${page.pageNum!}</span> / ${page.pages!}
                        <p>
                            <input type="text" id="gotoPage"/>
                            <a href="javascript:void(0)" class="go" onclick="goto($('#gotoPage').val())">GO</a>
                        </p>
                        <div class="pnt">
                            <a href="javascript:void(0)" class="prev" onclick="pre()"></a>
                            <a href="javascript:void(0)" class="next" onclick="next()"></a>
                        </div>
                    </div>
                [#else]
                    <div style="text-align: center">当前没有任何财务信息~</div>
                [/#if]
            </div>
        </div>
    </div>

    [#include "/front/common/front_footerAzt.html"]
</div>

<!-- 公司信息悬浮框Template -->
<script type="text/html" id="companyTip">
    <div class="tan-companyInfo" style="width:280px;  [#if !ispurchaser][: if(this.isChild==true) { :] left:218px;[: }:][/#if]" >
        <div style="text-align: center; padding-top: 35px;[: if(this.companyName?true : false) { :] display: none; [: } :]">
            <img src="/res/third/nice-validator/images/loading.gif" alt="loading"/>
        </div>
        <div [: if(this.companyName?false : true) { :] style="display: none;" [: } :]>
            <em></em>
            <div class="pic"><img src="[:=this.logo||'/res/images/temppic2.jpg':]" alt="" /></div>
            <div class="des">
                <p style="white-space: nowrap">[:=this.companyName||'':]</p>
                <p>[:=this.regProvince||'':] [:=this.regCity||'':]</p>
                <p>[:=this.userName||'':]     [:=this.contact||'':]</p>
            </div>
        </div>
    </div>
</script>

<!-- 分批支付悬浮框Template -->
<script type="text/html" id="batchPayTip">
    <div class="pctitle">分批付款</div>
    <em></em>
    <ul>
        [: for(var i = 0, len = list.length; i < len; i++) { :]
        <li class="[: if(i != len - 1) { :]first[: } :][: if(i == len - 1) { :]on[: } :]">
            <div class="num"><i></i><span>[:= i + 1 :]</span></div>
            <p class="price"><span class="orange">¥[:=list[i].payPrice.toFixed(2):]</span></p>
            [: if(list[i].payResult == 1) { :]
            <p>支付凭证审核中</p>
            [: } :]
            [: if(list[i].payResult == 3) { :]
            <p>支付待复核</p>
            [: } :]
            [: if(list[i].ppState == 1) { :]
            <p>支付待解冻</p>
            [: } :]
            <p>[:=list[i].payTime:]</p>
        </li>
        [: } :]
    </ul>
</script>

<!-- 分批支付未支付悬浮框Template -->
<script type="text/html" id="batchPayUnpaidTip">
    <div class="pctitle">分批付款</div>
    <em></em>
    <ul>
        [: for(var i = 0, len = list.length; i < len; i++) { :]
        <li class="[: if(i != len - 1) { :]first[: } :][: if(i == len - 1) { :]on[: } :]">
            <div class="num"><i></i><span>[:= i + 1 :]</span></div>
            <p class="price"><span class="orange">¥[:=list[i].payPrice:]</span></p>
            [: if(list[i].payResult == 1) { :]
            <p>支付凭证审核中</p>
            [: } :]
            [: if(list[i].payResult == 3) { :]
            <p>支付待复核</p>
            [: } :]
            [: if(list[i].ppState == 1) { :]
            <p>支付待解冻</p>
            [: } :]
            <p>[:=list[i].payTime:]</p>
        </li>
        [: } :]
        [: if(this.unPayPrice) { :]
        <li>
            <div class="num"><i></i><span>[:= len + 1 :]</span></div>
            <p class="price"> 剩余<span class="orange">¥[:=this.unPayPrice||'':]</span></p>
        </li>
        [: } :]
    </ul>
</script>

<!-- 提醒 -->
<div class="tanbox tanTip" style="display:none;">
    <div class="tanbg"></div>
    <div class="box" style="width:400px;">
        <span class="closed" onclick="close()"></span>
        <div class="cont">
            <div class="des">
                <h4>提醒</h4>
                <p>无法支付，该订单存在异常。</p>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/res/js/common/jquery.1.9.1.min.js"></script>
<script type="text/javascript" src="/res/js/structure/struture.js"></script>
<script type="text/javascript" src="/res/js/common/common.js"></script>
<script type="text/javascript" src="/res/third/laydate/laydate.js"></script>
<script type="text/javascript" src="/res/third/layer/layer.js"></script>
<script type="text/javascript" src="/res/js/common/tppl.js"></script>
<script type="text/javascript" src="/res/third/nice-validator/jquery.validator.min.js?local=zh-CN"></script>
<script type="text/javascript">
	var companyTipId = '';     //要展示公司tip的订单id（防止同一时间出现两个tip）

    $(function(){
    	$(".back-main .inner").css("minHeight",$(window).height()-200);
    	initTab();
    	initDate();
    	initCompanyTip();
    	initBatchPayTip() 

        function autoside(){
            $('.back-side').height($(window).height()-48);
            $('.warp').css('minHeight',$(window).height()-48);
        }

        $(window).resize(function(){
            autoside()
        }).trigger('resize');
        
        $(".back-main .inner").css("minHeight",$(window).height()-200);
    });
    
    function close(){
    	$('.tanbox').hide()
    }
    
  //展示公司信息tip信息
    function initCompanyTip() {
        $('.dataTable .alltd .cname').hover(function() {
            [#if ispurchaser]
                var companyId = $(this).parents('table').attr('data-sellerCompanyId');
                var userId = $(this).parents('table').attr('data-sellerUserId');
            [#else]
                var companyId = $(this).parents('table').attr('data-buyerCompanyId');
                var userId = $(this).parents('table').attr('data-buyerUserId');
            [/#if]
            if(!companyId || !userId) {
                return;
            }
            var container = $(this).find('div');
            companyTipId = $(this).parents('table').attr('data-orderid');
            ifChildBuy = $(this).parents('table').attr('data-ifChildBuy');
            //首先显示loading
            if(ifChildBuy == 'true'){
            	container.html(tppl($('#companyTip').html(), {isChild : true}));
            }else{
            	container.html(tppl($('#companyTip').html(), {isChild : false}));
            }

            $.ajax({
                url : '/order/loadCompanyTip',
                type : 'post',
                dataType : 'json',
                cache : true,
                data : {orderId : companyTipId, companyId : companyId, userId : userId},
                success : function(obj) {
                    if(obj.success) {
                        var data = obj.obj;
                        if(data.orderId == companyTipId) {
                            //保证同一时间只出现一个
                            data.isChild = (ifChildBuy == 'true');
                            container.html(tppl($('#companyTip').html(), data)); 
                        } else {
                            container.html('');
                        }
                    }
                }
            });

        },function() {
            companyTipId = '';
            $(this).find('div').html('');
        });
    }
    
    //公司信息
    function initHover(){
        var $tan_companyInfo = $('.tan-companyInfo');
        $('.dataTable .alltd .cname').hover(function(){
        	var companyid= 
            $(this).append($tan_companyInfo);
        },function(){
            $(this).find($tan_companyInfo).remove();
        });
    }
    
  //分批支付Tip
    function initBatchPayTip() {
        $('.pname[data-tip=batchPay]').hover(function() {
            var $container = $(this).parent().find('.pcdown');
            if($container.find('ul').length > 0) {
                //已经加载过，不再加载
                return;
            }
            var orderId = $(this).parents('table').attr('data-orderId');
            $.ajax({
                url : '/order/loadBatchPayTip',
                type : 'post',
                dataType : 'json',
                data : {orderId : orderId},
                success : function(data) {
                    if(data.success) {
                        $container.html(tppl($('#batchPayTip').html(), data.obj));
                    }
                    var sz=$container.find("li").length;  
                    $container.find("ul").width(130*sz); 
                   /*  $container.find("em").css("left",130*sz+20); */
                }
            });
        }, function() {
        });
        
        $('.pname[data-tip=batchPayUnpaid]').hover(function() {
            var $container = $(this).parent().find('.pcdown');
            if($container.find('ul').length > 0) {
                //已经加载过，不再加载
                return;
            }
            var orderId = $(this).parents('table').attr('data-orderId');
            $.ajax({
                url : '/order/loadBatchPayTip',
                type : 'post',
                dataType : 'json',
                data : {orderId : orderId},
                success : function(data) {
                    if(data.success) {
                        $container.html(tppl($('#batchPayUnpaidTip').html(), data.obj));
                    }
                    var sz=$container.find("li").length;  
                    $container.find("ul").width(130*sz); 
                    /* $container.find("em").css("left",130*sz+20); */
                }
            });
        }, function() {
        });
    }
    //tab绑定点击事件
    function initTab() {
        $('li[data-tab]').on('click', function() {
            var tab = $(this).attr('data-tab');
            $('#payResult').val(tab);
            $('#orderPayForm input').not(':hidden').val('');
            $('#buyerId').val("");
            search();
        });
    }
    
   	//日期选择控件初始化
    function initDate() {
        var start = {
            elem: '#sdate',
            format: 'YYYY-MM-DD',
        [#if queryParam.edate??]
            max : '${queryParam.edate}',
        [/#if]
            choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas;//将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#edate',
            format: 'YYYY-MM-DD',
        [#if queryParam.sdate??]
            min : '${queryParam.sdate}',
            start : '${queryParam.sdate}',
        [/#if]
            choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
    }
    
    function search() {
        $('#pageNo').val(1);
        $('#orderPayForm').submit();
    }

    function next() {
        goto(Number($('#pageNo').val()) + 1);
    }

    function pre() {
        goto(Number($('#pageNo').val()) - 1);
    }

    function goto(pageNo) {
        if(pageNo >= 1 && pageNo <= ${page.pages!}) {
            $('#pageNo').val(pageNo);
            $('#orderPayForm').submit();
        }
    }

    function checkPay(orderId) {
        $.ajax({
            url : '/order/checkPay',
            type : 'post',
            dataType : 'json',
            async : false,
            data : {orderId : orderId},
            beforeSend : function() {
                layer.load(2, {shade: 0.1});
            },
            success : function(data) {
                if(data.success) {
                    var url = '/order/pay/' + orderId + '/' + data.obj;
                    window.open(url);   //todo 浏览器拦截
                } else {
                    layer.alert(data.msg);
                }
            },
            complete : function() {
                layer.closeAll('loading');
            }
        })
    }
</script>
</body>
</html>
